/*
 * Copyright (c) 2022 Institute of Software Chinese Academy of Sciences (ISCAS)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Copyright (c) 2023 Institute of Software Chinese Academy of Sciences (ISCAS)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package space.ao.services.support.redis;

import io.quarkus.redis.datasource.RedisDataSource;
import io.quarkus.redis.datasource.keys.KeyCommands;
import io.quarkus.redis.datasource.value.ValueCommands;
import jakarta.enterprise.context.ApplicationScoped;

import java.util.List;

@ApplicationScoped
public class RedisCommonStringService {
  private final KeyCommands<String> keyCommands;
  private final ValueCommands<String, String> countCommands;

  public RedisCommonStringService(RedisDataSource ds) {
    countCommands = ds.value(String.class);
    keyCommands = ds.key();
  }

  public void setex(String key, String value, long expire) {
    countCommands.setex(key, expire, value);
  }

  public void expire(String key, long expire) {
    keyCommands.expire(key, expire);
  }

  public void set(String key, String value) {
    countCommands.set(key, value);
  }

  public int del(String key) {
    return keyCommands.del(key);
  }

  public String get(String key) {
    return countCommands.get(key);
  }

  public List<String> keys(String s) {
    return keyCommands.keys(s);
  }

  public long incr(String key) {
    return countCommands.incr(key);
  }
}
